<template>
		<view class="rules">
				<view class="rules_content" v-show='isRules'>
					<u-parse 
						className="rules_cell"
						:content="eventRules"
						@preview="preview"
						@navigate="navigate"
						/>
				</view>
		</view>
</template>

<script>
	import {authorizedDetail,auditDetail} from  "@/common/api.js";
	import uParse from '@/components/uni-parse/parse.vue'
	export default{
		data(){
			return{
				eventRules:"",
				org_id:"",
				id:"",
				examine_id:"",
				auditData:{},
				isRules:false,
				isAuditRule:false
			}
		},
		components:{
			uParse
		},
		onLoad(e){
			var _this=this;
			if(e.examine_id){
				_this.examine_id=e.examine_id;
				_this.isAuditRule=true;
			}else{
				_this.id=e.id;
				_this.org_id=e.org_id
				_this.isAuditRule=false;
			}
				// _this.loadRules()
		},
		onShow() {
			var _this=this;
			_this.isRules=false;
			_this.loadRules();
			setTimeout(function(){
				_this.isRules=true;
			},1000)
		},
		onUnload() {
			var _this=this;
			_this.eventRules='';
			_this.isRules=false;
		},
		methods:{
			loadRules(){
				var _this=this;
				_this.isRules=true;
				if(_this.isAuditRule){
					_this.getAuditRule();
				}else{
					_this.getAuthorizedRule();
				}
			},
			getAuthorizedRule(){
				var _this=this,data={
					id:_this.id,
					org_id:_this.org_id
				}
				authorizedDetail(data).then(function(res){
						var e=res.data;
						if(e.errcode==0){
							if(e.data.eventinfo&&e.data.eventconfig==null){
								try{
								  _this.eventRules = decodeURIComponent(e.data.eventinfo.condition)
								}catch(err){
								  _this.eventRules =e.data.eventinfo.condition;
								}
							}
							if(_this.eventRules==""||_this.eventRules==null){
								var authorizedData=JSON.parse(e.data.eventconfig.jsondataevent)
								try{
									_this.eventRules = decodeURIComponent(authorizedData.eventnotice)
								}catch(err){
									_this.eventRules =authorizedData.eventnotice
								}
							}
							// console.log(_this.eventRules)
						}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
							uni.showToast({
								title:e.msg,
								icon:"none"
							})
						}
					}).catch(function(res){
						uni.showToast({
							position: 'center',
							icon: 'none',
							title: res.msg
						});
					})
				},
				getAuditRule(){
					var _this=this;
					var data={examine_id:_this.examine_id}
					auditDetail(data).then(function(res){
						var e=res.data;
						if(e.errcode==0){
							if(e.event_new){
								_this.auditData=JSON.parse(e.event_new);
							}else{
								_this.auditData=JSON.parse(e.event_old);
							}
							try{
								_this.eventRules = decodeURIComponent(_this.auditData.eventnotice)
							}catch(err){
								_this.eventRules =_this.auditData.eventnotice;
							}
						}else{
							uni.showToast({
								position: 'center',
								icon: 'none',
								title: e.msg
							});
						}
					})
				},
				//预览图片时触发
				preview(src, e) {
					// do something
				},
				//点击链接时触发
				navigate(href, e) {
					// do something
				},
			}
		}
</script>

<style lang="less" scoped >
	.rules{
		background: #F6F7F9;
		// font-size: 14px;
		font-size: 16px;
		// height: 100vh;
		.blue{
			color: #2D8DFF;
		}
		.red{
			color: #FF535A;
		}
		.green{
			color: #81D25A;
		}
	}
	// .wrapper{
	// 	display: flex;
	// 	flex-flow: column;
	// }
	.signup_header{
		position: relative;
		padding: 5px 0;
		height: 24px;
		font-size: 18px;
		text-align: center;
		background: #fff;
		border-bottom: 1px solid #F1F1F2;
		.back{
			position: absolute;
			left: 0;
			top: 0;
		}
	}
	.rules_content{
			padding: 11px 12px 13px;
			background: #fff;
			margin: 14px;
			border-radius: 8px;
			min-height: 127px;
	}
	// .rules_cell{
		// image{
		// 	width: 375px !important;
		// 	height: 200px !important;
		// }
	// }
	
</style>
